<?php

namespace app\app\controller;

use app\common\controller\Homebase;
use EasyWeChat\Factory;
use think\Db;
use think\facade\Cache;
use think\Validate;
use think\Request;
use OSS\OssClient;
use OSS\Core\OssException;

class Index extends Homebase
{
    protected function initialize()
    {
        parent::initialize();
    }

    /**
     * 获取openid
     */
    public function wxLogin()
    {
        $code = $this->request->param("code");
        $appId = config('wechat.appID');
        $secret = config('wechat.AppSecret');
        $url = 'https://api.weixin.qq.com/sns/jscode2session?appid=' . $appId . '&secret=' . $secret . '&js_code=' . $code . '&grant_type=authorization_code';
        $res = lmcurl($url);
        msg(0, "成功", $res);
    }

    /**
     * 上传图片
     */
    // todo 转换成webp 看图片压缩
    public function upload_img()
    {
        $files = $this->request->file('file');//获取图片
        $info = $files->move(ROOT_PATH . 'public' . '/' . 'uploads');

        if ($info) {

            $logo = '/' . 'uploads' . '/' . $info->getSaveName();

            $datas = $info->getInfo();

            $img['path'] = $logo;

            $img['mime'] = $datas['type'];

            $img['name'] = $datas['name'];

            $img['size'] = $datas['size'];

            $img['sha1'] = $info->hash('sha1');

            $img['md5'] = $info->hash('md5');

            $img['driver'] = 'local';

            $img['create_time'] = time();

            $img['update_time'] = time();

            $img['status'] = 1;

            $img['ext'] = $info->getExtension();

            $id = Db::name('attachment')->insertGetId($img);
            //todo 关闭oss
//            if (config('is_oss') == 1) {
//                upload_local_file($id);
//            }
            $d = db('attachment')->where('id', $id)->find();
            if ($d['type'] == 1) {
                $d['path'] = conf("wechat", "url") . str_replace('\\', '/', $d['path']);
            } else {
                $d['path'] = conf("wechat", "url") . $d['path'];
            }
            msg(0, "获取成功", $d);

        } else {
            echo $files->getError();
        }
        //msg(0, "成功", $url);
    }

    /**
     * 获取手机号
     */
    public function getPhone()
    {
        try {
            $data = $this->request->param();
            $config = config('wechat.config');
            $app = Factory::miniProgram($config);
            $data = $app->phone_number->getUserPhoneNumber($data['code']);
            msg(0, '查询成功', $data);
        } catch (\Exception $e) {
            msg(-1, $e->getMessage(), date('Y-m-d H:i:s'));
        }
    }

    /**
     * @return void 保存用户信息
     */
    public function deuser()
    {
        $data = $this->request->param();

        $datas['openid'] = $data['openid'];

        $datas['reg_ip'] = $this->request->ip();

        $datas['mobile'] = $data['mobile'];

        $datas['nickname'] = $data['nickname'];

        $datas['avatarUrl'] = $data['avatarUrl'];

        if (isset($data['invite_id']) && $data['invite_id']) {
            //获取上级member_id
            $datas['invite_id'] = InviteId($data['invite_id']);
        }

        $rules = [
            'openid' => 'require',
            'mobile' => 'require',
//            'nickname' => 'require',
//            'avatarUrl' => 'require',
        ];
        $message = [
            'openid.require' => 'openid必须',
            'mobile.require' => '手机必须',
//            'nickname.require' => '昵称必须',
//            'avatarUrl.require' => '头像必须',
        ];
        $validate = new Validate($rules, $message);
        $result = $validate->check($data);
        if (!$result) {
            msg(-1, '缺少信息', '');
        }
        $stmt = Db::name('member')->where('openid', $datas['openid'])->find();
        if ($stmt) {
            $datas['last_login_time'] = time();
            unset($datas['nickname']);
            unset($datas['avatarUrl']);
            if ($stmt['is_clock'] == 1) {
                unset($datas['invite_id']);
            }
            Db::name('member')->where('openid', $datas['openid'])->update($datas);
            $member = Db::name('member')->where('openid', $datas['openid'])->find();
            if ($member['status'] == 0) {
                responseJson(-200, '用户已冻结', $member);
            }
            msg(0, '查询成功', $member);
        } else {
            $datas['create_time'] = time();
            $datas['status'] = 1;
            //一键默认登录 设置默认昵称 默认头像
            $datas['nickname'] = '用户' . rand(00000, 99999);
            $datas['avatarUrl'] = config('site.web_default_avatar');
            //邀请用户
            if (isset($data['invite_id'])) {

            }
            $user_id = Db::name('member')->insertGetId($datas);
            msg(0, '新建成功', $datas);
        }
    }

    /**
     * 获取各项配置
     */
    public function getConfigAdmin()
    {
        $data = $this->request->param();
        if ($data['set_name'] && isset($data['set_name'])) {
            msg(0, '查询完成', config('site.' . $data['set_name']));
        }
        msg(-1, '请输入查询内容', '');
    }

    /**
     * 获取banner图
     */
    public function getBanner()
    {
        $return_data = Db::name('banner')
            ->where(['status' => 1, 'is_del' => 0])
            ->order('sort desc')
            ->find();
        msg(0, '查询成功', $return_data);
    }

    /**
     * 获取商品分类
     */
    public function getCateList()
    {
        $return_data = Db::name('goods_cate')
            ->where(['status' => 1, 'is_del' => 0])
            ->order('sort desc')
            ->select();
        foreach ($return_data as $k => $v) {
            if ($k == 0) {
                $return_data[$k]['is_able'] = 1;
            } else {
                $return_data[$k]['is_able'] = 0;
            }
        }
        msg(0, '查询成功', $return_data);
    }

    /**
     * 获取商品分类
     */
    public function getCateList2()
    {
        $return_data = Db::name('goods_cate')
            ->where(['status' => 1, 'is_del' => 0])
            ->order('sort desc')
            ->select();
        msg(0, '查询成功', $return_data);
    }

    /**
     * 获取通知公告
     */
    public function getNotice()
    {
        $notice_list = Db::name('notice')->where([
            'status' => 1,
            'is_del' => 0,
        ])->select();
        msg(0, '查询成功', $notice_list);
    }

    /**
     * 首页商品列表 限制每项3个
     */
    public function indexGoods()
    {
        $cate_list = Db::name('goods_cate')
            ->where(['is_del' => 0, 'status' => 1])
            ->order('sort desc')
            ->select();
        foreach ($cate_list as $k => $v) {
            $goods_list = Db::name('goods')
                ->where(['is_del' => 0, 'status' => 1])
                ->order('sort desc')
                ->limit(3)
                ->select();
            foreach ($goods_list as $k2 => $v2) {
                $goods_attr_value = Db::name('goods_attr_value')->where([
                    'goods_id' => $v2['id']
                ])->find();
                $goods_list[$k2]['goods_attr_value'] = $goods_attr_value;
            }
            $cate_list[$k]['goods_list'] = $goods_list;
        }
        msg(0, '查询成功', $cate_list);
    }



    //活动商品列表
    public function getGoodsListHd()
    {
        $data = $this->request->param();
        $page = input('page/d', 1);
        $length = input('limit/d', 20);
        $order_type = input('order_type/d', 1);
        switch ($order_type) {
            case 1:
                $sort = 'sort desc';
                break;
            case 2:
                $sort = 'price';
                break;
            case 3:
                $sort = 'sale_num desc';
                break;
            default:
                $sort = 'sort desc';
        }
        $where[] = ['is_del', '=', 0];
        $where[] = ['status', '=', 1];
        $where[] = ['is_hd', '=', 1];
        if (isset($data['name']) && $data['name']) {
            $where[] = ['name', 'like', '%' . $data['name'] . '%'];
        }
        if (isset($data['cate_id']) && $data['cate_id']) {
            $where[] = ['cate_id', '=', $data['cate_id']];
        }
        $goods_list = Db::name('goods')
            ->where($where)
            ->order($sort)
            ->paginate($length, false, [
                'page' => $page
            ])->each(function ($item) {
                $goods_attr_value = Db::name('goods_attr_value')->where([
                    'goods_id' => $item['id']
                ])->find();
                $item['goods_attr_value'] = $goods_attr_value;
                return $item;
            });
        msg(0, '查询成功', $goods_list);
    }

    //健康区商品列表
    public function getJKGoodsList()
    {
        $data = $this->request->param();
        $page = input('page/d', 1);
        $length = input('limit/d', 20);
        $order_type = input('order_type/d', 1);
        switch ($order_type) {
            case 1:
                $sort = 'sort desc';
                break;
            case 2:
                $sort = 'price';
                break;
            case 3:
                $sort = 'sale_num desc';
                break;
            default:
                $sort = 'sort desc';
        }
        $where[] = ['is_del', '=', 0];
        $where[] = ['status', '=', 1];
        $where[] = ['goods_area', '=', 4];
        if (isset($data['name']) && $data['name']) {
            $where[] = ['name', 'like', '%' . $data['name'] . '%'];
        }
        if (isset($data['cate_id']) && $data['cate_id']) {
            $where[] = ['cate_id', '=', $data['cate_id']];
        }
        $goods_list = Db::name('goods')
            ->where($where)
            ->order($sort)
            ->paginate($length, false, [
                'page' => $page
            ])->each(function ($item) {
                $goods_attr_value = Db::name('goods_attr_value')->where([
                    'goods_id' => $item['id']
                ])->find();
                $item['goods_attr_value'] = $goods_attr_value;
                return $item;
            });
        msg(0, '查询成功', $goods_list);
    }

    //商品规格
    public function getGoodsAttr()
    {
        $data = $this->request->param();
        $goods_attr_value = Db::name('goods_attr_value')->where([
            'goods_id' => $data['id']
        ])->select();
        foreach ($goods_attr_value as $k => $v) {
            if ($k == 0) {
                $goods_attr_value[$k]['is_select'] = 2;
            } else {
                $goods_attr_value[$k]['is_select'] = 1;
            }

        }
        msg(0, '查询成功', $goods_attr_value);
    }

    //首页三张分类背景
    public function getIndexCateBg()
    {
        $data = config('site.web_cate_img');
        $return_data = array();
        $name = array('1', '2', '3');
        foreach ($data as $k => $v) {
            $return_data[$name[$k]] = $v;
        }
        msg(0, '查询成功', $return_data);
    }

    //获取素材列表
    public function getMaterial()
    {
        $data = $this->request->param();
        $page = input('page/d', 1);
        $length = input('limit/d', 20);
        $where[] = ['is_del', '=', 0];
        $where[] = ['status', '=', 1];
        $data_list = Db::name('material')->where($where)
            ->order('sort desc')
            ->paginate($length, false, [
                'page' => $page
            ])->each(function ($item) {
                $item['img'] = explode(',', $item['img']);
                $item['open'] = false;
                return $item;
            });
        msg(0, '查询成功', $data_list);
    }

    //获取素材详情
    public function getMaterialDetail()
    {
        $data = $this->request->param();
        $material_data = Db::name('material')->find($data['id']);
        $material_data['img'] = explode(',', $material_data['img']);
        msg(0, '查询成功', $material_data);
    }

    //地址相关
    //购物车
    //素材中心
    //视频列表
    //

    public function file_upload(Request $request)
    {
        $status = 1;
        $data = [];
        if ($request->Method() == 'POST') {
            $file = $request->file('file');
//            dump($file->getInfo('size'));
//            die;
            $size = formatSizeUnits($file->getInfo('size'));
            // 移动到框架应用根目录/upload/ 目录下
            $info = $file->move('upload/video');
            if ($info) {
                //把反斜杠(\)替换成斜杠(/) 因为在windows下上传路是反斜杠径
                $getSaveName = str_replace("\\", "/", $info->getSaveName());
                $fileUrl = '/upload/video/' . $getSaveName;
                $data['url'] = $fileUrl;
                $data['size'] = $size;
                $message = '上传成功';
            } else {
                $message = "上传失败 " . $file->getError();
            }
        } else {
            $message = "参数错误";
        }
        return showMsg($status, $message, $data);
    }

    public function upload_fileOss()
    {
        $oss_config = config('wechat.oss');
        $ossClient = new OssClient($oss_config['AccessKeyId'], $oss_config['AccessKeySecret'], $oss_config['endpoint']);

        $uploadedFile = $_FILES['file'];
        $fileName = $uploadedFile['name'];
        $fileTmpPath = $uploadedFile['tmp_name'];
        $directory = 'video/';
        $exist = $ossClient->doesObjectExist($oss_config['bucket'], $directory);

        if (!$exist) {
            // 创建目录
            try {
                $ossClient->createObjectDir($oss_config['bucket'], $directory);
            } catch (OssException $e) {
                msg(-1, '目录创建失败：' . $e->getMessage(), 0);
//                echo '目录创建失败：' . $e->getMessage();
//                exit;
            }
        }
        try {
            $object = $directory . $fileName;
            $data = $ossClient->uploadFile($oss_config['bucket'], $object, $fileTmpPath);
            $return_data['url'] = $data['info']['url'];
            $return_data['size'] = formatSizeUnits($data['info']['size_upload']);
            return showMsg(1, '上传成功', $return_data);
//            msg(0, '查询成功', $data['info']);
            echo '文件上传成功！';
        } catch (OssException $e) {
            msg(-1, $e->getMessage(), 0);
            echo '文件上传失败：' . $e->getMessage();
        }
    }

    //首页视频列表
    public function videoList()
    {
        $video_list = Db::name('video')
            ->where([])
            ->limit(3)
            ->order('sort desc')
            ->select();
        msg(0, '查询成功', $video_list);
    }


    //首页分区
    public function index_top()
    {
        $data = Db::name('goods_area')
            ->where([
                'is_del' => 0,
                'status' => 1
            ])
            ->order('sort desc')
            ->select();
        $return['bg1'] = $data[0];
        $return['bg2'] = $data[1];
        $return['bg3'] = $data[2];
        msg(0, '查询更改', $return);
    }

    //首页视频 todo 视频
    public function indexVideo()
    {
        $data = Db::name('video')->where([
            'is_del' => 0,
            'status' => 1
        ])->find();
        msg(0, '查询更改', $data);
    }

    //首页砍价商品
    public function indexKjGoods()
    {
        $goods_list = Db::name('goods')
            ->where(['is_del' => 0, 'status' => 1, 'goods_area' => 3])
            ->order('sort desc')
            ->limit(3)
            ->select();
        foreach ($goods_list as $k2 => $v2) {
            $goods_attr_value = Db::name('goods_attr_value')->where([
                'goods_id' => $v2['id']
            ])->find();
            $goods_list[$k2]['goods_attr_value'] = $goods_attr_value;
        }
        msg(0, '查询成功', $goods_list);
    }

    //大家都在砍
    public function allKjGoods()
    {
        $goods_list = Db::name('goods')
            ->where(['is_del' => 0, 'status' => 1, 'goods_area' => 3, 'recommend' => 1])
            ->order('sort desc')
            ->limit(4)
            ->select();
        foreach ($goods_list as $k2 => $v2) {
            $goods_attr_value = Db::name('goods_attr_value')->where([
                'goods_id' => $v2['id']
            ])->find();
            $goods_list[$k2]['goods_attr_value'] = $goods_attr_value;
        }
        msg(0, '查询成功', $goods_list);
    }

    //首页拼团商品
    public function indexPtGoods()
    {
        $goods_list = Db::name('goods')
            ->where(['is_del' => 0, 'status' => 1, 'goods_area' => 1])
            ->order('sort desc')
            ->limit(3)
            ->select();
        foreach ($goods_list as $k2 => $v2) {
            $goods_attr_value = Db::name('goods_attr_value')->where([
                'goods_id' => $v2['id']
            ])->find();
            $goods_list[$k2]['goods_attr_value'] = $goods_attr_value;
        }
        msg(0, '查询成功', $goods_list);
    }

    //推荐拼团
    public function recommendPtGoods()
    {
        $goods_list = Db::name('goods')
            ->where(['is_del' => 0, 'status' => 1, 'goods_area' => 1, 'recommend' => 1])
            ->order('sort desc')
            ->limit(6)
            ->select();
        foreach ($goods_list as $k2 => $v2) {
            $goods_attr_value = Db::name('goods_attr_value')->where([
                'goods_id' => $v2['id']
            ])->find();
            $goods_list[$k2]['goods_attr_value'] = $goods_attr_value;
        }
        msg(0, '查询成功', $goods_list);
    }

    //首页热门推荐
    public function recommonGoods()
    {
        $page = input('page/d', 1);
        $length = input('limit/d', 20);

        $goods_list = Db::name('goods')
            ->where(['is_del' => 0, 'status' => 1, 'goods_area' => 2, 'recommend' => 1])
            ->order('sort desc')
            ->paginate($length, false, [
                'page' => $page
            ])->each(function ($item) {
                $goods_attr_value = Db::name('goods_attr_value')->where([
                    'goods_id' => $item['id']
                ])->find();
                $item['goods_attr_value'] = $goods_attr_value;
                return $item;
            });
        msg(0, '查询成功', $goods_list);
    }

    //拼团专区商品列表
    public function getPTGoodsList()
    {
        $data = $this->request->param();
        $page = input('page/d', 1);
        $length = input('limit/d', 20);
        $order_type = input('order_type/d', 1);
        switch ($order_type) {
            case 1:
                $sort = 'sort desc';
                break;
            case 2:
                $sort = 'price';
                break;
            case 3:
                $sort = 'sale_num desc';
                break;
            default:
                $sort = 'sort desc';
        }
        $where[] = ['is_del', '=', 0];
        $where[] = ['status', '=', 1];
        $where[] = ['goods_area', '=', 1];
        if (isset($data['name']) && $data['name']) {
            $where[] = ['name', 'like', '%' . $data['name'] . '%'];
        }
        if (isset($data['cate_id']) && $data['cate_id']) {
            $where[] = ['cate_id', '=', $data['cate_id']];
        }
        $goods_list = Db::name('goods')
            ->where($where)
            ->order($sort)
            ->paginate($length, false, [
                'page' => $page
            ])->each(function ($item) {
                $goods_attr_value = Db::name('goods_attr_value')->where([
                    'goods_id' => $item['id']
                ])->find();
                $item['goods_attr_value'] = $goods_attr_value;
                return $item;
            });
        msg(0, '查询成功', $goods_list);
    }

    //砍价区商品列表
    public function getKjGoodsList()
    {
        $data = $this->request->param();
        $page = input('page/d', 1);
        $length = input('limit/d', 20);
        $order_type = input('order_type/d', 1);
        switch ($order_type) {
            case 1:
                $sort = 'sort desc';
                break;
            case 2:
                $sort = 'price';
                break;
            case 3:
                $sort = 'sale_num desc';
                break;
            default:
                $sort = 'sort desc';
        }
        $where[] = ['is_del', '=', 0];
        $where[] = ['status', '=', 1];
        $where[] = ['goods_area', '=', 3];
        if (isset($data['name']) && $data['name']) {
            $where[] = ['name', 'like', '%' . $data['name'] . '%'];
        }
        if (isset($data['cate_id']) && $data['cate_id']) {
            $where[] = ['cate_id', '=', $data['cate_id']];
        }
        $goods_list = Db::name('goods')
            ->where($where)
            ->order($sort)
            ->paginate($length, false, [
                'page' => $page
            ])->each(function ($item) {
                $goods_attr_value = Db::name('goods_attr_value')->where([
                    'goods_id' => $item['id']
                ])->find();
                $item['goods_attr_value'] = $goods_attr_value;
                return $item;
            });
        msg(0, '查询成功', $goods_list);
    }

    public function getAddressByCity()
    {
        $data = $this->request->param();
        //当前维度 经度 搜索关键字 页数 所在市
        $data_list = getAddressByLocation2($data['latitude'], $data['longitude']);
        $data_list = json_decode($data_list, true);
        if ($data_list['code'] == 0) {
            $data_list['data']['location']['lat'] = $data['latitude'];
            $data_list['data']['location']['lng'] = $data['longitude'];
            msg(0, '查询成功', $data_list['data']);
        } else {
            msg(-1, $data_list['data'], '');
        }
    }

    //获取健康信息
    public function getHealInfo()
    {
        $return['health_name'] = config('site.health_name');
        $return['health_img'] = config('site.health_img');
        $return['heal_tag'] = explode(',', config('site.heal_tag'));
        $return['zx_num'] = config('site.zx_num');
        $return['health_detail'] = config('site.health_detail');
        $return['phone'] = config('site.phone');
        $return['health_name'] = config('site.health_name');
        msg(0, '查询成功', $return);
    }

    //拼团成功列表
    public function PtSList()
    {
        $data_list = Db::name('order')
            ->alias('o')
            ->join('member m', 'm.id=o.member_id')
            ->field('o.*,m.nickname,m.avatarUrl')
            ->order('o.create_time desc')
            ->where([
                ['o.status', 'in', [2, 3, 4, 5, 8]],
                ['o.pin_type', '=', 1],
                ['o.order_type', '=', 1]
            ])->limit(20)->select();
        foreach ($data_list as $k => $v) {
            $data_list[$k]['nickname'] = maskString($v['nickname']);
        }
        msg(0, '查询成功', $data_list, count($data_list));
    }

    //砍价成功列表
    public function bargainSList()
    {
        $data_list = Db::name('order')
            ->alias('o')
            ->join('member m', 'm.id=o.member_id')
            ->field('o.*,m.nickname,m.avatarUrl')
            ->order('o.create_time desc')
            ->where([
                ['o.status', 'in', [2, 3, 4, 5, 8]],
                ['o.can_type', '=', 1],
                ['o.order_type', '=', 3]
            ])->limit(20)->select();
        foreach ($data_list as $k => $v) {
            $data_list[$k]['nickname'] = maskString($v['nickname']);
        }
        msg(0, '查询成功', $data_list, count($data_list));
    }


    //获取分享拼团详情
    public function getPtOrderDetail2()
    {
        $data = $this->request->param();
        $group_activities_id = $data['group_activities_id'];
        $group_activities = Db::name('group_activities')->find($group_activities_id);

        $order_info = Db::name('order')->where([
            'activity_id' => $group_activities_id,
            'member_id' => $group_activities['member_id']
        ])->find();
        $order_goods = Db::name('order_goods')->where([
            'order_id' => $order_info['id']
        ])->find();
        $where = array(
            'g.id' => $order_goods['goods_id'],
            'gav.suk' => $order_goods['suk']
        );
        $goods_info = Db::name('goods')->alias('g')
            ->join('goods_attr_value gav', 'g.id=gav.goods_id')
            ->field('g.*,gav.suk,gav.stock,gav.sale_num,gav.price,gav.pin_price')
            ->where($where)
            ->find();

        $group_participants = Db::name('group_participants')->alias('gr')
            ->field('gr.*,m.nickname,m.avatarUrl')
            ->join('member m', 'm.id=gr.member_id')
            ->order('gr.create_time')->where([
                'gr.group_active_id' => $group_activities_id
            ])->select();
        $c_num = $group_activities['group_num'] - count($group_participants);
        for ($i = $c_num; $i > 0; $i--) {
            $group_participants[] = [];
        }
        $return_data['order_info'] = $order_info;
        $return_data['goods_info'] = $goods_info;
        $return_data['group_activities'] = $group_activities;
        $return_data['group_participants'] = $group_participants;
        msg(0, '查询完成', $return_data);
    }


    //直接退款
    public function tui()
    {
        $data = $this->request->param();
        $order_id = $data['id'];
        $order_info = Db::name('order')
            ->where('id', $order_id)
            ->find();
        $config = config('wechat.wxpay');
        $app = Factory::payment($config);

        $tui_money = $order_info['pay_money'];

        $result = $app->refund->byOutTradeNumber($order_info['order_no'], $order_info['order_no'], $order_info['pay_money'] * 100, $tui_money * 100, [
            // 可在此处传入其他参数，详细参数见微信支付文档
            'refund_desc' => '订单退款',
        ]);
        msg(0, '查询更改', $result);
    }

    //砍价详情
    public function getBargainDetail()
    {
        $data = $this->request->param();
        $bargain_info = Db::name('bargain_activity')->find($data['bargain_activity_id']);
        $where = array(
            'g.id' => $bargain_info['goods_id'],
            'gav.suk' => $bargain_info['suk']
        );
        $goods_info = Db::name('goods')->alias('g')
            ->join('goods_attr_value gav', 'g.id=gav.goods_id')
            ->field('g.*,gav.suk,gav.stock,gav.sale_num,gav.price,gav.min_price')
            ->where($where)
            ->find();
        $bargain_info['cut_money_sum'] = round($bargain_info['price'] - $bargain_info['current_price'], 2);
        $bargain_info['need_cut_money'] = round($bargain_info['current_price'] - $bargain_info['target_price'], 2);
        $return_data['goods_info'] = $goods_info;
        $return_data['bargain_info'] = $bargain_info;
        msg(0, '查询完成', $return_data, '');
    }

    //获取商品属性值
    public function getGoodsAttr2()
    {
        $data = $this->request->param();
        $return_data = Db::name('goods_attribute_value')->where([
            'is_del' => 0,
            'goods_id' => $data['id']
        ])->order('sort desc')
            ->select();
        msg(0, '查询成功', $return_data);
    }

    //获取上级的 最近 小店 市店 董事 cc
    public function getUpperLevelIds3()
    {
        $data = $this->request->param();
        $result = getSuperiorShops($data['member_id']);
        $data2 = filterEntities($result);
        msg(0, '查询成功', $data2);
    }

    //获取 快递物流
    public function getExpress()
    {
        $data = $this->request->param();
        Db::startTrans();
        try {
            $express_info = queryExpress(config('wechat.express_key'), config('wechat.express_customer'), $data['express_code'], $data['express_no']);
            if ($express_info['status'] == 200) {
                msg(0, '查询成功', $express_info['data']);
            } else {
                msg(-1, '无效信息', $express_info);
            }
        } catch (\Exception $e) {
            Db::rollback();
            msg(-1, $e->getMessage(), '');
        }
    }

    //---------------------首页接口-----------------------------
    public function cIndex()
    {
        $member_num = Db::name('member')->where('openid', '<>', '')->count();
        $order_num = Db::name('order')->where('status', 'in', [2, 3, 4, 5, 8, 9, 10])->count();
        $goods_num = Db::name('goods')->where('is_del', 'in', [0])->count();
        $video_num = Db::name('points_goods')->where([
            'is_del' => 0
        ])->count();
        $data['a'] = $member_num;
        $data['b'] = $order_num;
        $data['c'] = $goods_num;
        $data['d'] = $video_num;
        msg(0, '查询更改', $data);
    }

    public function cIndex2()
    {
        $order_money = Db::name('order')->where('status', 'in', [2, 3, 4, 5, 8, 9, 10])->sum('pay_money');
        $tui_money = Db::name('order')->where('pay_status', 'in', [2])->sum('tui_moeny');

        $dai = Db::name('member')->sum('money');
        $dai2 = Db::name('shop')->sum('money');
        $ti_zhong = Db::name('member_finance')->where([
            ['type', 'in', [6]],
            ['is_kuan', 'in', [0]],
        ])->sum('money');
        $ti_zhong2 = Db::name('shop_finance')->where([
            ['type', 'in', [2]],
            ['is_kuan', 'in', [0]],
        ])->sum('money');
        $send_money = Db::name('member_finance')->where([
            ['type', 'in', [6]],
            ['is_kuan', 'in', [1]],
        ])->sum('money');
        $send_money2 = Db::name('shop_finance')->where([
            ['type', 'in', [2]],
            ['is_kuan', 'in', [1]],
        ])->sum('money');


        $data['a'] = round($order_money, 2);
        $data['b'] = $tui_money;
        $data['c'] = round($dai + $dai2, 2);
        $data['d'] = round($ti_zhong + $ti_zhong2, 2);
        $data['e'] = round($send_money + $send_money2, 2);
        msg(0, '查询更改', $data);
    }

    public function getPie()
    {
        $return_data = array();
        $gc_list = Db::name('goods_cate')->where([
            'is_del' => 0
        ])->select();
        foreach ($gc_list as $k => $v) {
            $goods_ids = Db::name('goods')->where([
                'cate_id' => $v['id']
            ])->column('id');
            $num = Db::name('order_goods')->alias('og')
                ->where('o.status', 'in', [2, 3, 4, 5, 8, 9, 10])
                ->join('order o', 'o.id=og.order_id')
                ->where([
                    ['goods_id', 'in', $goods_ids],
                ])->count();
            $return_data[$k]['name'] = $v['name'];
            $return_data[$k]['value'] = $num;
        }
        msg(0, '查询更改', $return_data);
    }

    public function getbar()
    {
        $list = Db::name('order_goods')->alias('og')
            ->join('order o', 'o.id=og.order_id')
            ->field('og.goods_id, SUM(og.num) AS total_num')
            ->where('o.status', 'in', [3, 4, 5, 6])
            ->group('og.goods_id')
            ->order('total_num DESC')
            ->limit(10)
            ->select();
        // 关联商品表获取商品名称
        $goodsIds = array_column($list, 'goods_id');
        $goodsNames = Db::name('goods')
            ->where('id', 'in', $goodsIds)
            ->column('name', 'id');
        // 合并商品名称到结果中
        foreach ($list as &$item) {
            $item['goods_name'] = $goodsNames[$item['goods_id']] ?? '商品';
        }
        $data1 = array();
        $data2 = array();
        foreach ($list as $k => $v) {
            $data1[] = $v['goods_name'];
            $data2[] = $v['total_num'];
        }
        $return_data['data1'] = $data1;
        $return_data['data2'] = $data2;
        msg(0, '查询更改', $return_data);
    }
    //todo  定时任务 砍价活动定时任务 订单完成 订单取消 订单支付完成  自动升级 市店 董事
    //订单取消定时 1min
    public function orderCancelTime()
    {
        Db::startTrans();
        try {
            //订单状态 1待发货 2已发货 3已完成
            $limit = 20;
            $page = Cache::get('getAccount_page');
            if (!$page) {
                $page = 1;
                Cache::set('getAccount_page', $page);
            }
            $order_where = [
                ['status', '=', 1],
            ];
            $order_list = Db::name('order')
                ->page($page, $limit)
                ->where($order_where)
                ->order('create_time')
                ->select();
            if (!$order_list) {
                $page = 1;
                Cache::set('getAccount_page', $page);
                msg(100, '订单为空', '');
            }
            $config = config('wechat.wxpay');
            $app = Factory::payment($config);
            foreach ($order_list as $k => $item) {
                //判断订单是否微信支付
                //1待支付 2待发货  3待收货 4待核销 5已完成 6已评价 7已取消 8退款售后 9待配送
                $res = $app->order->queryByOutTradeNumber($item['order_no']);
                if ($res['trade_state'] != "SUCCESS") {
                    if (time() - $item['create_time'] >= 1200) {
                        Db::name('order')->update([
                            'id' => $item['id'],
                            'status' => 7,
                        ]);
                    }
                }
            }
            Cache::set('getAccount_page', ++$page);
            Db::commit();
            msg(100, '操作完成', '');
        } catch (\Exception $e) {
            Db::rollback();
            msg(-1, $e->getMessage(), date('Y-m-d H:i:s'));
        }
    }

    //砍价活动定时
    public function bargainActiveEnd()
    {
        Db::startTrans();
        try {
            //订单状态 1待发货 2已发货 3已完成
            $limit = 20;
            $page = Cache::get('getAccount_page2');
            if (!$page) {
                $page = 1;
                Cache::set('getAccount_page2', $page);
            }
            $where = [
                ['status', '=', 0],
            ];
            $list = Db::name('bargain_activity')
                ->page($page, $limit)
                ->where($where)
                ->order('create_time')
                ->select();
            if (!$list) {
                $page = 1;
                Cache::set('getAccount_page2', $page);
                msg(100, '订单为空', '');
            }
            foreach ($list as $k => $item) {
                if ($item['end_time'] < time()) {
                    Db::name('bargain_activity')->update([
                        'id' => $item['id'],
                        'status' => 2,
                    ]);
                }
            }
            Cache::set('getAccount_page2', ++$page);
            Db::commit();
            msg(100, '操作完成', '');
        } catch (\Exception $e) {
            Db::rollback();
            msg(-1, $e->getMessage(), date('Y-m-d H:i:s'));
        }
    }

    //自动订单完成 发货完成后
    public function orderFinishTime()
    {
        Db::startTrans();
        try {
            $limit = 60;
            $page = Cache::get('getAccount_page3');
            if (!$page) {
                $page = 1;
                Cache::set('getAccount_page3', $page);
            }
            $order_where = [
                //1待支付 2待发货  3待收货 4待核销 5已完成 6已评价 7已取消 8退款售后 9待配送
                ['status', '=', 3],
            ];
            $order_list = Db::name('order')
                ->page($page, $limit)
                ->where($order_where)
                ->order('create_time')
                ->select();
            if (!$order_list) {
                $page = 1;
                Cache::set('getAccount_page3', $page);
                msg(100, '订单为空', '');
            }
            foreach ($order_list as $k => $item) {
                $day_num = config('site.web_day_num') ? config('site.web_day_num') : 2;
                $days_diff = getDaysDiff($item['express_time']); //express_time send_time
                if ($days_diff >= $day_num) {
                    finishOrder($item, 2);
                }
            }
            Cache::set('getAccount_page3', ++$page);
            Db::commit();
            msg(100, '操作完成', '');
        } catch (\Exception $e) {
            Db::rollback();
            msg(-1, $e->getMessage(), date('Y-m-d H:i:s'));
        }
    }

    //用户等级不能下降 升级市店
    public function uPDirector()
    {
        Db::startTrans();
        try {
            $limit = 60;
            $page = Cache::get('getAccount_page4');
            if (!$page) {
                $page = 1;
                Cache::set('getAccount_page4', $page);
            }
            $member_list = Db::name('member')
                ->page($page, $limit)
                ->where('level_id', '=', 3)
                ->select();
            if (!$member_list) {
                $page = 1;
                Cache::set('getAccount_page4', $page);
                msg(100, '用户为空', '');
            }
            Cache::set('getAccount_page4', ++$page);
            foreach ($member_list as $k => $v) {
                $return = isCityShop($v['id']);
                if ($return) {
                    Db::name('member')->update([
                        'id' => $v['id'],
                        'level_id' => 4
                    ]);
                }
            }
            Db::commit();
            msg(0, '', date('Y-m-d H:i:s'));
        } catch (\Exception $e) {
            Db::rollback();
            msg(-1, $e->getMessage(), date('Y-m-d H:i:s'));
        }
    }

    //升级股东
    public function uPShareholder()
    {
        Db::startTrans();
        try {
            $limit = 60;
            $page = Cache::get('getAccount_page5');
            if (!$page) {
                $page = 1;
                Cache::set('getAccount_page5', $page);
            }
            $member_list = Db::name('member')
                ->page($page, $limit)
                ->where('level_id', '=', 4)
                ->select();
            if (!$member_list) {
                $page = 1;
                Cache::set('getAccount_page5', $page);
                msg(100, '用户为空', '');
            }
            Cache::set('getAccount_page5', ++$page);
            foreach ($member_list as $k => $v) {
                $return = isDongshi($v['id']);
                if ($return) {
                    Db::name('member')->update([
                        'id' => $v['id'],
                        'level_id' => 5
                    ]);
                }
            }
            Db::commit();
            msg(0, '', date('Y-m-d H:i:s'));
        } catch (\Exception $e) {
            Db::rollback();
            msg(-1, $e->getMessage(), date('Y-m-d H:i:s'));
        }
    }

    //定时任务订单支付完成 2秒一次
    public function getOrderPay()
    {
        Db::startTrans();
        try {
            $limit = 60;
            $page = Cache::get('getAccount_page6');
            if (!$page) {
                $page = 1;
                Cache::set('getAccount_page6', $page);
            }
            $order_where = [
                ['status', '=', 1],//1待支付
            ];
            $order_list = Db::name('order')
                ->page($page, $limit)
                ->where($order_where)
                ->order('create_time desc')
                ->select();

            if (!$order_list) {
                $page = 1;
                Cache::set('getAccount_page6', $page);
                msg(100, '订单为空', '');
            }
            Cache::set('getAccount_page6', ++$page);
            $config = config('wechat.wxpay');
            $app = Factory::payment($config);
            foreach ($order_list as $k => $item) {
                $res = $app->order->queryByOutTradeNumber($item['order_no']);
                if ($res['trade_state'] == "SUCCESS") {
                    if ($item['order_type'] == 2 || $item['order_type'] == 4 || $item['pin_type'] == 2 || $item['can_type'] == 2) {
                        orderPaySuccess($item);
                    }
                }
            }

            Db::commit();
            msg(0, '', date('Y-m-d H:i:s'));
        } catch (\Exception $e) {
            Db::rollback();
            msg(-1, $e->getMessage(), date('Y-m-d H:i:s'));
        }
    }

    //定时任务参与拼团 完成支付
    public function joinPtOrder()
    {
        Db::startTrans();
        try {
            $limit = 60;
            $page = Cache::get('getAccount_page8');
            if (!$page) {
                $page = 1;
                Cache::set('getAccount_page8', $page);
            }
            $order_where = [
                ['status', '=', 1],//1待支付 2待发货 3待收货 4已完成 5已评价 6售后退货 7已取消 8待取货 9拼团待完成10砍价发起
                ['order_type', '=', 1],//1拼团区 2臻品区 3砍价区 4健康区
                ['pin_type', '=', 1],//1拼团购买 2直接购买
            ];
            $order_list = Db::name('order')
                ->page($page, $limit)
                ->where($order_where)
                ->order('create_time desc')
                ->select();

            if (!$order_list) {
                $page = 1;
                Cache::set('getAccount_page8', $page);
                msg(100, '订单为空', '');
            }
            Cache::set('getAccount_page8', ++$page);
            $config = config('wechat.wxpay');
            $app = Factory::payment($config);
            foreach ($order_list as $k => $item) {
                $res = $app->order->queryByOutTradeNumber($item['order_no']);
                if ($res['trade_state'] == "SUCCESS") {
                    PtOrderPaySuccess2($item);
                }
            }
            Db::commit();
            msg(0, '', date('Y-m-d H:i:s'));
        } catch (\Exception $e) {
            Db::rollback();
            msg(-1, $e->getMessage(), date('Y-m-d H:i:s'));
        }
    }

    public function order_additional_notify()
    {
        $config = config('wechat.wxpay');
        $app = Factory::payment($config);
        $response = $app->handlePaidNotify(function ($message, $fail) {
            Db::name('pay_log')->insert([
                'content' => json_encode($message),
                'time' => time()
            ]);
            if ($message['return_code'] == 'SUCCESS') {
                if ($message['result_code'] == 'SUCCESS') {
                    $order_data = Db::name('order')
                        ->where('order_no', '=', $message['out_trade_no'])
                        ->find();
                    if ($order_data['status'] == 1) {
                        payOrderSuccess($order_data);
                    }
                }
            } else {
                return $fail('FAIL');
            }
            return true;
        });
        $response->send();
    }

    //回调测试
    public function order_notify2()
    {
        $data = $this->request->param();
        $order_info = Db::name('order')->where('order_no', '=', $data['order_no'])->find();
        if ($order_info['status'] == 1) {
            payOrderSuccess($order_info);
        }
        msg(0, '查询成功', $order_info);
    }

    //精选榜单商品
    public function jxGoodsList()
    {
        $data = $this->request->param();
        $page = input('page/d', 1);
        $length = input('limit/d', 20);
        $where[] = ['is_del', '=', 0];
        $where[] = ['status', '=', 1];
        $where[] = ['recommend', '=', 1];
        $where[] = ['goods_area', '=', 2];
//        $where[] = ['is_jx', '=', 1];
        $data_list = Db::name('goods')->where($where)
            ->order('sort desc')
            ->paginate($length, false, [
                'page' => $page
            ])->each(function ($item) {
                $item['img'] = $item['first_img'];
                $goods_attr_value = Db::name('goods_attr_value')->where([
                    'goods_id' => $item['id']
                ])->find();
                $item['goods_attr_value'] = $goods_attr_value;
                return $item;
            });
        msg(0, '查询成功', $data_list);
    }


    //首页新人礼列表显示
    public function indexGift()
    {
        //获取新人券
        //获取新人积分
        $fraction_num = config('site.web_new_jf') ? config('site.web_new_jf') : 200;
        $coupons = Db::name('coupons')->where([
            'cate_id' => 1,
            'is_del' => 0
        ])->order('sort desc')->select();
        $return_data[] = array(
            'num' => $fraction_num,
            'type' => 1,
            'desc' => '专属积分',
            'img_bg' => config('site.coupons_new_bg')
        );
        foreach ($coupons as $k => $v) {
            $return_data[] = array(
                'num' => $v['value'],
                'type' => 2,
                'desc' => '优惠券',
                'img_bg' => config('site.coupons_new_bg')
            );
        }
        $title = '老客专享会员好礼';
        $return_data2['list'] = $return_data;
        $return_data2['title'] = $title;
        msg(0, '查询成功', $return_data2);
    }

    //积分商城列表 优惠卷列表
    public function fractionShopList1()
    {
        $data = $this->request->param();
        $page = input('page/d', 1);
        $length = input('limit/d', 20);
        $where[] = ['is_del', '=', 0];
        $where[] = ['status', '=', 1];
        $where[] = ['goods_type', '=', 1];
        $data_list = Db::name('points_goods')->where($where)
            ->order('sort desc')
            ->paginate($length, false, [
                'page' => $page
            ])->each(function ($item) {
                $coupons = Db::name('coupons')->find($item['object_id']);
                $coupons['yx'] = $coupons['effect_day'] . '天可用';
                $coupons['img'] = config('site.coupons_bg');
                $item['coupons'] = $coupons;
                $item['coupons'] = $coupons;
                return $item;
            });
        msg(0, '查询成功', $data_list);
    }

    //积分商城列表 生活用品
    public function fractionShopList2()
    {
        $data = $this->request->param();
        $page = input('page/d', 1);
        $length = input('limit/d', 20);
        $where[] = ['is_del', '=', 0];
        $where[] = ['status', '=', 1];
        $where[] = ['goods_type', '=', 2];
        $data_list = Db::name('points_goods')->where($where)
            ->order('sort desc')
            ->paginate($length, false, [
                'page' => $page
            ])->each(function ($item) {
                $coupons = Db::name('coupons')->find($item['object_id']);
                return $item;
            });
        msg(0, '查询成功', $data_list);
    }

    //积分商城列表 汽车配件
    public function fractionShopList3()
    {
        $data = $this->request->param();
        $page = input('page/d', 1);
        $length = input('limit/d', 20);
        $where[] = ['is_del', '=', 0];
        $where[] = ['status', '=', 1];
        $where[] = ['goods_type', '=', 3];
        $data_list = Db::name('points_goods')->where($where)
            ->order('sort desc')
            ->paginate($length, false, [
                'page' => $page
            ])->each(function ($item) {
                $coupons = Db::name('coupons')->find($item['object_id']);
                return $item;
            });
        msg(0, '查询成功', $data_list);
    }

    //积分商品详情
    public function pointFoodsDetail()
    {
        $data = $this->request->param();
        $goods_info = Db::name('points_goods')->find($data['id']);

        msg(0, '查询成功', $goods_info);
    }

    public function prizeOrderList()
    {
        $prizes = Db::name('prize_goods')
            ->order('sort desc')
            ->where('status', '=', 1)
            ->where('is_del', '=', 0)
            ->where('stock', '>', 0)
            ->limit(8)
            ->select();
        $obj = [
            [
                'name' => config('site.prize_jf') . '积分一次',
                'probability' => -1
            ]
        ];
        array_splice($prizes, 4, 0, $obj);
        msg(0, '查询完成', $prizes, count($prizes));
    }

    //获取品牌列表
    public function brand()
    {
        $goods_list = Db::name('brand')
            ->where([
                'is_del' => 0,
                'status' => 1
            ])->order('sort desc')->select();
        foreach ($goods_list as $k=>$v){
            $goods_list[$k]['is_able']=0;
        }
        msg(0, '查询完成', $goods_list);
    }

    //todo 抽奖记录后台管理
    public function a2()
    {
        $a = strtotime('8:00');
        return $a;
    }

    //获取秒杀时间列表
    public function xsList()
    {
        $data_list = Db::name('xsms_time')
            ->where([
                'status' => 1,
                'is_del' => 0
            ])
            ->order('start_time')
            ->select();
        foreach ($data_list as $k => $v) {
            $start_time = strtotime($v['start_time']);
            $end_time = $start_time + ($v['delayed_time'] * 60);
            $data_list[$k]['end_time'] = $end_time;
            //在秒中的
            //goods is_ms 是否正在秒杀 1是 2不是
            if (time() >= $start_time && time() <= $end_time) {
                $data_list[$k]['is_able'] = 1;
                $data_list[$k]['title'] = '火热抢购中';
            } else {
                $data_list[$k]['is_able'] = 0;
                $data_list[$k]['title'] = '即将开抢';
            }
        }
        msg(0, '查询完成', $data_list);
    }

    //获取秒杀商品
    public function xsGoods()
    {
        $data = $this->request->param();
        $page = input('page/d', 1);
        $length = input('limit/d', 20);

        $where[] = ['is_del', '=', 0];
        $where[] = ['status', '=', 1];
        $where[] = ['goods_area', '=', 1];
        $where[] = ['ms_id', '=', $data['xs_id']];

        $goods_list = Db::name('goods')
            ->where($where)
            ->order('sort desc')
            ->paginate($length, false, [
                'page' => $page
            ])->each(function ($item) {
                $goods_attr_value = Db::name('goods_attr_value')->where([
                    'goods_id' => $item['id']
                ])->find();
                if ($item['is_ms'] == 2) {
                    $item['is_able'] = 0;
                    $item['icon_img'] = config('site.ms0');
                } else {
                    $item['is_able'] = 1;
                    $item['icon_img'] = config('site.ms1');
                }
                $goods_attr_value['ms_stock'] = $goods_attr_value['stock'];
                $goods_attr_value['jiang_price'] = $goods_attr_value['old_price'] - $goods_attr_value['price'];
                //ms_price todo 使用秒杀价格
                $item['goods_attr_value'] = $goods_attr_value;
                return $item;
            });
        msg(0, '查询成功', $goods_list);

//        $where[] = ['g.is_del', '=', 0];
//        $where[] = ['g.status', '=', 1];
//        $where[] = ['xsg.status', '=', 2];
//        $where[] = ['xsg.xs_id', '=', $data['xs_id']];
//
//        $goods_list = Db::name('goods')->alias('g')
//            ->join('xs_goods xsg', 'g.id=xsg.goods_id')
//            ->field('g.*,xsg.price as ms_price')
//            ->where($where)
//            ->order('g.sort desc')
//            ->paginate($length, false, [
//                'page' => $page
//            ])->each(function ($item) {
//                $goods_attr_value = Db::name('goods_attr_value')->where([
//                    'goods_id' => $item['id']
//                ])->find();
//                if ($item['is_ms'] == 2) {
//                    $item['is_able'] = 0;
//                    $item['icon_img'] = config('site.ms0');
//                } else {
//                    $item['is_able'] = 1;
//                    $item['icon_img'] = config('site.ms1');
//                }
//                $goods_attr_value['ms_stock'] = $goods_attr_value['stock'];
//                $goods_attr_value['price'] = $item['ms_price'];
//                $goods_attr_value['jiang_price'] = $goods_attr_value['old_price'] - $goods_attr_value['price'];
//                //ms_price todo 使用秒杀价格
//                $item['goods_attr_value'] = $goods_attr_value;
//                return $item;
//            });

    }
    //修改用户优惠金额 秒杀商品没有优惠
    //首页秒杀接口
    public function indexMsGoods()
    {
        $data_list = Db::name('xsms_time')
            ->where([
                'status' => 1,
                'is_del' => 0
            ])
            ->order('start_time')
            ->select();
        foreach ($data_list as $k => $v) {
            $start_time = strtotime($v['start_time']);
            $end_time = $start_time + ($v['delayed_time'] * 60);
            $data_list[$k]['start_time'] = $start_time;
            $data_list[$k]['end_time'] = $end_time;
            //在秒中的
            //goods is_ms 是否正在秒杀 1是 2不是
            if (time() >= $start_time && time() <= $end_time) {
                $ms_data = $v;
            }
        }
        if ($ms_data) {
            $xsms_time = Db::name('xsms_time')->find($ms_data['id']);
            $start_time = strtotime($xsms_time['start_time']);
            $end_time = $start_time + ($xsms_time['delayed_time'] * 60);
            $xsms_time['start_time1'] = $start_time;
            $xsms_time['end_time'] = $end_time;

//            $where[] = ['g.is_del', '=', 0];
//            $where[] = ['g.status', '=', 1];
//            $where[] = ['xsg.status', '=', 2];
//            $where[] = ['xsg.xs_id', '=', 8];
            $where[] = ['is_del', '=', 0];
            $where[] = ['status', '=', 1];
            $where[] = ['goods_area', '=', 1];
            $where[] = ['is_ms', '=', 1];
            $where[] = ['ms_id', '=', $ms_data['id']];


            $goods_list = Db::name('goods')
                ->where($where)
                ->order('sort desc')->select();
//            $goods_list = Db::name('goods')->alias('g')
//                ->join('xs_goods xsg', 'g.id=xsg.goods_id')
//                ->field('g.*,xsg.price as ms_price')
//                ->where($where)
//                ->limit(2)
//                ->order('g.sort desc')
//                ->select();
//            $goods_list = Db::name('goods')->alias('g')
//                ->join('xs_goods xsg', 'g.id=xsg.goods_id')
//                ->field('g.*,xsg.price as ms_price')
//                ->where($where)
//                ->limit(2)
//                ->order('g.sort desc')
//                ->select();
            foreach ($goods_list as $k => $v) {
                $goods_attr_value = Db::name('goods_attr_value')->where([
                    'goods_id' => $v['id']
                ])->find();
//                $goods_attr_value['price'] = $v['ms_price'];
                //ms_price todo 使用秒杀价格
                $goods_list[$k]['goods_attr_value'] = $goods_attr_value;
            }
            $return_data['xsms_time'] = $xsms_time;
            $return_data['goods_list'] = $goods_list;
            msg(0, '查询成功', $return_data);
        } else {
            $return_data['xsms_time'] = null;
            $return_data['goods_list'] = [];
            msg(-1, '查询成功', $return_data);
        }
    }

    //获取商户信息
    public function getShopInfo2()
    {
        //todo 发布生成添加员工的二维码 生成路径
        $shop = Db::name('shop')
            ->where(['is_del' => 0])
            ->find();
        msg(0, '查询完成', $shop);
    }
    //获取商品大类
    public function getCate1List()
    {
        $return_data = Db::name('cate1')
            ->where(['status' => 1, 'is_del' => 0])
            ->order('sort desc')
            ->select();
        foreach ($return_data as $k => $v) {
            if ($k == 0) {
                $return_data[$k]['is_able'] = 1;
            } else {
                $return_data[$k]['is_able'] = 0;
            }
        }
        msg(0, '查询成功', $return_data);
    }



}